﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCCommon.CRMEnums;
using BCDto.CRM.CustomerInfo;
using BCService.CRM.CustomerInfo;

namespace BCTMSRESTful.Controllers.Management.CRM.CustomerInfo
{

    /// <summary>
    /// 客户信息
    /// </summary> 
    [ApiExplorerSettings(GroupName = "CRMAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class CustomerInfoController :ManagementBaseController
    {
        #region var
        private ICustomerInfoService cCustomerInfoService;
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public CustomerInfoController(ICustomerInfoService ccCustomerInfoService)
        {
            this.cCustomerInfoService = ccCustomerInfoService;
        }
        #endregion

        #region POST
        /// <summary>
        /// 创建客户信息记录
        /// </summary>
        /// <response code="200">成功。</response>
        [HttpPost]        
        [ProducesResponseType(typeof(int), 200)]
        public IActionResult Post([FromBody]CustomerInfoRequestDto dto)
        { 
            var a = this.cCustomerInfoService.AddNew(Admin,dto);
            return Ok(a);
        }
        #endregion

        #region PUT
        /// <summary>
        /// 修改客户信息记录
        /// </summary>
        /// <response code="200">成功。</response>
        [HttpPut]        
        [ProducesResponseType(typeof(int), 200)]
        public IActionResult Put([FromBody]CustomerInfoDto dto)
        {
            var a = Ok(cCustomerInfoService.Update(dto,Admin));
            return a;
        }
        #endregion

        #region Delete
        /// <summary>
        /// 删除客户信息记录
        /// </summary>
        /// <param name="customerInfoId"></param>
        /// <returns></returns>
        [HttpDelete("{customer_info_id}")]        
        [ProducesResponseType(typeof(CustomerInfoDto), 200)]
        public IActionResult Delete([FromRoute(Name = "customer_info_id")]long customerInfoId)
        {
            cCustomerInfoService.Delete(Admin,customerInfoId);
            return NoContent();
        }
        #endregion

        #region GetByID 
        /// <summary>
        /// 获取客户信息记录
        /// </summary>
        /// <response code="200">成功。</response>
        [HttpGet("{customer_info_id}")]        
        [ProducesResponseType(typeof(CustomerInfoDto), 200)]
        public IActionResult GetByID([FromRoute(Name = "customer_info_id")]long ccCustomerInfoId)
        {
            var a = Ok(cCustomerInfoService.GetByID(ccCustomerInfoId));
            return a;
        }
        #endregion

        #region 查询客户信息列表
        /// <summary>
        /// 查询客户信息列表
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Phone"></param>
        /// <param name="ResourceType"></param>
        /// <param name="CustomerType"></param>
        /// <param name="IsFill"></param>
        /// <param name="ProvinceCode"></param>
        /// <param name="CityCode"></param>
        /// <param name="CountyCode"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]        
        [ProducesResponseType(typeof(PageableList<CustomerInfoDto>), 200)]
        public IActionResult GetCustomerInfoList(
            [FromQuery(Name = "user_name")]string UserName,
            [FromQuery(Name = "phone")]string Phone,
            [FromQuery(Name = "resource_type")]CRMResourceType? ResourceType,
            [FromQuery(Name = "customer_type")]CRMCustomerType? CustomerType,
            [FromQuery(Name = "is_fill")]bool? IsFill,
            [FromQuery(Name = "province_code")]string ProvinceCode,
            [FromQuery(Name = "city_code")]string CityCode,
            [FromQuery(Name = "county_code")]string CountyCode,
            [FromQuery(Name = "index")]int? pageIndex = 1,
            [FromQuery(Name = "size")]int? pageSize = 10
            )
        {
            string fResourceType = ResourceType == null ? null : ResourceType.ToString();
            string fCustomerType = CustomerType == null ? null : CustomerType.ToString();
 
            var a = cCustomerInfoService.GetList(Admin,UserName, Phone, fResourceType, fCustomerType, IsFill, ProvinceCode, CityCode, CountyCode, pageIndex.Value, pageSize.Value);
            return Ok(a);
        }
        #endregion
    }
}